﻿namespace DesignModeConsole.行为型.状态模式.MarioSample;

/// <summary>
/// 分支逻辑法
/// </summary>
public class MarioStateMachine1
{
    public int Score { get; private set; }
    public StateEnum CurrentState { get; private set; }

    public MarioStateMachine1()
    {
        Score = 0;
        CurrentState = StateEnum.Small;
    }

    /// <summary>
    /// 得到蘑菇
    /// </summary>
    public void ObtainMushRoom()
    {
        if (CurrentState == StateEnum.Small)
        {
            CurrentState = StateEnum.Super;
            Score += 100;
        }
    }


    /// <summary>
    /// 得到斗篷
    /// </summary>
    public void ObtainCape()
    {
        if (CurrentState is StateEnum.Small or StateEnum.Super)
        {
            CurrentState = StateEnum.Cape;
            Score += 200;
        }
    }

    /// <summary>
    /// 得到火焰
    /// </summary>
    public void ObtainFireFlower()
    {
        if (CurrentState is StateEnum.Small or StateEnum.Super)
        {
            CurrentState = StateEnum.Fire;
            Score += 300;
        }
    }

    /// <summary>
    /// 遇到怪物
    /// </summary>
    public void MeetMonster()
    {
        if (CurrentState == StateEnum.Super)
        {
            CurrentState = StateEnum.Small;
            Score -= 100;
            return;
        }

        if (CurrentState == StateEnum.Cape)
        {
            CurrentState = StateEnum.Small;
            Score -= 300;
            return;
        }

        if (CurrentState == StateEnum.Fire)
        {
            CurrentState = StateEnum.Small;
            Score -= 300;
        }
    }
}